package com.itheima.a09threadsafe1;

public class MyThread  extends Thread{

    //表示ticket变量被所有线程共享
    static int ticket=0; //0-100

    //锁对象一定要是唯一的
    static Object obj=new Object();
    @Override
    public void run() {
            while (true) {
                synchronized (MyThread.class) {
                if (ticket < 100) {

                    ticket++;
                    System.out.println(getName() + "正在卖第" + ticket + "张票！！！");
                } else {
                    break;
                }
            }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
    }
}
